
function give_me_three (t, from, to)
	local square_line = ''
	local i = from
	while i <= to do
		square_line = square_line..t[i]..' '
		i = i+1
	end
	return square_line
end

function create_square ()
	local new_square = {}
	local i= 1
		while i<10 do
			new_square[i]='.'
			i = i+1
		end
		function new_square:_turn_CW ()
			local switch_positions = {3,6,9,2,5,8,1,4,7}
			local new_square = {}
				for i,v in ipairs(switch_positions) do
					new_square[v] = self[i]
				end
			local j= 1
				while j<10 do
					self[j] = new_square[j]
					j = j+1
				end
		end
		function new_square:_turn_CCW ()
			local switch_positions = {7,4,1,8,5,2,9,6,3}
			local new_square = {}
				for i,v in ipairs(switch_positions) do
					new_square[v] = self[i]
				end
			local j= 1
				while j<10 do
					self[j] = new_square[j]
					j = j+1
				end
		end
	return new_square
end



--[[function turn_CW (square)
	local switch_positions = {3,6,9,2,5,8,1,4,7}
	local new_square = {}
	for i,v in ipairs(switch_positions) do
		new_square[v] = square[i]
	end
	return new_square
end
]]
function create_board()
	local new_board = {A = create_square(),
		B = create_square(),
		C = create_square(),
		D = create_square(),}
	function new_board:_update_board ()
	--local new_board = {}
		self[1] = '+-------+-------+'
		self[2] = '| '..give_me_three(self.A,1,3)..'| '..give_me_three(self.B,1,3)..'|'
		self[3] = '| '..give_me_three(self.A,4,6)..'| '..give_me_three(self.B,4,6)..'|'
		self[4] = '| '..give_me_three(self.A,7,9)..'| '..give_me_three(self.B,7,9)..'|'
		self[5] = '+-------+-------+'
		self[6] = '| '..give_me_three(self.C,1,3)..'| '..give_me_three(self.D,1,3)..'|'
		self[7] = '| '..give_me_three(self.C,4,6)..'| '..give_me_three(self.D,4,6)..'|'
		self[8] = '| '..give_me_three(self.C,7,9)..'| '..give_me_three(self.D,7,9)..'|'
		self[9] = '+-------+-------+'
	--return new_board
	end
	function new_board:_print_board ()
		for line, v in ipairs(self) do
			print(self[line])
		end
		print('\n')
	end
	return new_board
end

board = create_board()
--ex_sq = create_square()
board.A[1]='W'
board.A[6]='B'
board.C[5]='B'
board.D[9]='W'
board:_update_board()
board:_print_board()
board.A:_turn_CW()
board.D:_turn_CW()
board:_update_board()
board:_print_board()
board.A:_turn_CCW()
board.D:_turn_CCW()
board:_update_board()
board:_print_board()
--print_board(ex_sq)
--print_board(ex_sq)
